﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using NUnit.Framework;
using log4net.Config;

namespace DataLoadingModule.ViewModel.LoadDataSet
{
        [TestFixture]
        public class TestDataParser
        {

            private log4net.ILog _log = log4net.LogManager.GetLogger(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            [TestFixtureSetUp]
            public void Init()
            {
                XmlConfigurator.Configure();
                var rand = new Random();

            }

            [Test]
            public void DetermineBoundingCoords()
            {
                var dataOrder = new Dictionary<int, string>()
                                    {
                                        {0, "Object Id"},
                                        {1, "Trajectory Id"},
                                        {2, "Date"},
                                        {3, "Time"},
                                        {4, "Latitude"},
                                        {5, "Longitude"},
                                        {6, "X Coordinate"},
                                        {7, "Y Coordinate"}           
                                    };
                var parser = new DatasetParser(dataOrder, 
                    Path.Combine("E:\\UNI\\cp3046\\project\\development_code\\homestead-jcu_20_04_12\\Homestead.Jcu\\DataLoadingModule\\ViewModel\\LoadDataSet","MockData.txt"));

                var worker = new BackgroundWorker { WorkerReportsProgress = true };
                Boolean workerDone = false;
                var testPassed = false; 
                                    //1 is the passed state
                                    //0 is the running state

                worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
                {
                    _log.Info("TEST-DetermineBoundingCoords: maxX- "
+ parser.MaxX + " maxY - " + parser.MaxY + " minX- " + parser.MinX + " minY- " + parser.MinY);
                };

                worker.RunWorkerCompleted += (s, args) => //when its done
                                                 {
                                                     workerDone = true; //does not get here if assertion fails
                                                     Assert.AreEqual(42, parser.MaxX); //see MockData.txt for value
                                                     Assert.AreEqual(38, parser.MinX);
                                                     Assert.AreEqual(24, parser.MinY);
                                                     Assert.AreEqual(30, parser.MaxY);
                                                     testPassed = true; //this is the passed state


                                                 };

                worker.DoWork += delegate
                                     {
                                         parser.TryParse(";"[0], worker);
                                     };


                worker.RunWorkerAsync();

                while(!workerDone)
                {
                   _log.Info("waiting to finish...");
                    Thread.Sleep(100);
                }

                Assert.AreEqual(true, testPassed);

            }

        }
    }



